package com.example.github.networking;

import java.net.MalformedURLException;
import java.net.URL;

public class URLDemo {
    public static void main(String[] args) {
        /**
         * 1. 通过URL 获取url实例对象
         * 2. 使用url 实例对象调用openConnection() 方法打开连接
         * 3. 连接对象获取输入流
         * 4. 通过输入流读取内容
         */
        try {
            URL url=new URL("https://www.baidu.com/search?q=javatpoint&oq=javatpoint&sourceid=chrome&ie=UTF-8");
            System.out.println("Protocol: "+url.getProtocol());
            System.out.println("Host Name: "+url.getHost());
            System.out.println("Port Number: "+url.getPort());
            System.out.println("Default Port Number: "+url.getDefaultPort());
            System.out.println("Query String: "+url.getQuery());
            System.out.println("Path: "+url.getPath());
            System.out.println("File: "+url.getFile());
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }
}
